<?php
require_once realpath(dirname(__FILE__).'/../../app/init.php');
require_once 'AIR2_DBManager.php';

AIR2_DBManager::init();

/**
 * Creates doctrine models from your existing database's schema
 */

echo "********************************************************************************\n";
echo "*******    DATABASE SCHEMA TO MODELS                                  **********\n";
echo "********************************************************************************\n";
echo "    This will populate your 'models/' directory with the current database schema\n";
echo "    continue? (yes/no)\n    >";
$answer = strtoupper(trim(fgets(STDIN)));

if ($answer === 'YES' || $answer === 'Y') {
    try {
        // model path already defined in docrine_pi.php
        Doctrine::generateModelsFromDb(APPPATH.'/models');
        echo "    Model files generated from DB successfully!\n";
    } catch (Doctrine_Exception $e) {
        echo "    ERROR GENERATING MODELS FROM DB: ";
        echo $e->getMessage();
        echo "\n";
    }
} else {
    echo "    Doctrine Model classes have NOT been created\n";
}

echo "    exiting...\n\n";

?>
